﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace NTQOnlineExam.Services.Infrastructure.Utility
{
    public class NumberUtilities
    {
        public static int GetInt32(string value, int defaultValue)
        {
            if (value == null) return defaultValue;

            Regex regExp = new Regex("^[0123456789]+$|^-[0123456789]+$");
            if (regExp.Match(value.Trim()).Success == false)
                return defaultValue;

            int r;

            try
            {
                r = Int32.Parse(value.Trim());
            }
            catch
            {
                r = defaultValue;
            }
            return r;
        }

    }
}
